<?php
/**
  * Session.php
  *
  * This is not a freeware, use is subject to license terms
  * @author CLOUD DEV TEAM
  * 
  */
if (!defined('IN_CLOUD')) exit('Access Denied!');

class Session
{
	private static $object;

	/**
	 * 根据条件创建session实例
	 * @param unknown_type $type
	 */
	public static function createSession( $type )
	{
		$type = $type ? $type : 'mysql';
		if ( !is_object( self::$object[$type] ) )
		{
			switch ( $type )
			{
				case 'mysql' :
					self::$object[$type] = new Session_SessionMysql();	
				break;
				
				case 'file' :
					self::$object[$type] = new Session_SessionFile();
				break;
			}
		}
		return self::$object[$type];
	}
	
	/**
	 * 添加SESSION
	 * @param string $key
	 * @param string $value
	 */
	public static function set( $key , $value )
    {
    	$type = Common::getConfig( 'System' , 'session_type' );
    	self::createSession( $type );
    	$_SESSION[$key] = $value;
    }
    
    /**
     * 获取SESSION
     * @param string $key
     */
    public static function get( $key )
    {
    	$type = Common::getConfig( 'System' , 'session_type' );
    	self::createSession( $type );
    	return $_SESSION[$key];
    }
    
    /**
     * 获取sessionid
     */
    public static function getSessionId()
    {
    	return $_SESSION['session_id'];
    }
}